﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class wsd_add : FormBase1
    {
        public wsd_add()
        {
            InitializeComponent();
        }

        private void lue_dls_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind==DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
            {
                add_KF_DLS frm = new add_KF_DLS();
                frm.FatherRefresh = binddls;
                frm.ShowDialog();
            }
        }



        private void wsd_add_Load(object sender, EventArgs e)
        {
            dateEdit1.DateTime = DateTime.Now;
            binddls("");
            bindywxz("");
            bindtc("");
        }

        private void binddls(string title)
        {
            lue_dls.Properties.DataSource = my.bw.kf_dls_Get("", my.ACID);
            lue_dls.Text = title;
        }

        private void bindtc(string title)
        {
            lue_tc.Properties.DataSource = my.bw.kf_tc_Get("", my.ACID);
            lue_tc.Text = title;
        }

        private void lue_ywxz_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
            {
                add_ywxz frm = new add_ywxz();
                frm.FatherRefresh = bindywxz;
                frm.ShowDialog();
            }
        }

        private void bindywxz(string title)
        {
            lue_ywxz.Properties.DataSource = my.bw.ywxz_Get("", my.ACID);
            lue_ywxz.Text = title;
        }

        private void btn_OK_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            int? tcid = null;
            if (lue_dls.EditValue != null) tcid = int.Parse(lue_tc.EditValue.ToString());
            
            if (!dvp.Validate()) return;
            SVC.client.wsd wsd = new SVC.client.wsd();
            wsd.dlsid = int.Parse(lue_dls.EditValue.ToString());
            wsd.ywxzid = int.Parse(lue_ywxz.EditValue.ToString());
            wsd.jrh = te_jrh.Text;
            wsd.yhmc = te_yhmc.Text;
            wsd.yhlinktel = te_linktel.Text;
            wsd.tcid = tcid;
            wsd.yhadd = te_addr.Text;
            wsd.yhdk = te_DK.Text;
            wsd.fsp = te_fsp.Text;
            wsd.state = 0;
            string r = string.Empty;
            r = my.bw.wsd_Add(wsd, my.ACID);
            if (string.IsNullOrEmpty(r))
            {
                Comm.ShowInfo("新增数据成功");
                resetUI();
            }
            else
            {
                Comm.ShowErorr(r);
            }
        }

        private void resetUI()
        {
            lue_dls.EditValue = null;
            lue_ywxz.EditValue = null;
            dateEdit1.DateTime = DateTime.Now;
            te_jrh.Text = "";
            te_yhmc.Text = "";
            te_linktel.Text = "";
            te_DK.Text = "";
            lue_tc.EditValue = null;
            te_addr.Text = "";
            te_fsp.Text = "";
        }

        private void dateEdit1_EditValueChanged(object sender, EventArgs e)
        {
            if (dateEdit1.EditValue == null) return;
            te_pid.Text = my.bw.getBillNO(my.emp_lite.shopcode, dateEdit1.DateTime, 9, my.ACID);
        }

        private void lue_tc_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
            {
                add_kf_tc frm = new add_kf_tc();
                frm.FatherRefresh = bindtc;
                frm.ShowDialog();
            }
        }
    }
}